#include "Controller.h"

Controller::Controller( )
{
	m_Updating = false ;
	galaxy = new Galaxy( ) ;
}

Controller::~Controller( )
{
	delete galaxy ;
}

void Controller::InputCommand( char button, int x, int y )
{
	//Galaxy Map
	if( button == 'G' )
	{
		galaxy->WarpPlayer( x, y ) ;
		m_Updating = true ;
	}
	//Quadrant Map
	else if( button == 'Q' )
	{
		galaxy->UpdatePlayer( x, y ) ;
		cout << "Player moving to sector " << x << ", " << y << endl ;
		m_Updating = true ;
	}
	//Blasters
	else if( button == 'B' )
	{
		galaxy->SetBlasters( x ) ;
		m_Updating = true ;
	}
	//increase shields
	else if( button == '+' )
	{
		galaxy->PlayerShields( 100 ) ;
	}
	//decrease shields
	else if( button == '-' )
	{
		galaxy->PlayerShields( -100 ) ;
	}
	//Long Range Scanner
	else if( button == 'S' )
	{
		galaxy->ScanGalaxy( ) ;
	}
}

void Controller::UpdateGame( )
{
	//get the player's current information
	Player* tempPlayer = galaxy->GetPlayer( ) ;

	//if the player isn't IDLE this frame
	if( tempPlayer->GetState( ) != IDLE )
		galaxy->UpdatePlayer( NULL, NULL ) ;
	else
	{
		//Enemy's turn to move/attack
		galaxy->EnemyTurn( ) ;
		m_Updating = false ;
	}
}